package org.deltaset.samples.mvc.example;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import org.deltaset.meta.annotation.DsLabel;

/**
 *
 * @author dmakariev
 */
@Entity
public class OrderParent extends AbstractParent<OrderParent,OrderChild>{

    @OneToMany( fetch = FetchType.EAGER, cascade= CascadeType.ALL, orphanRemoval=true)
    @OrderColumn( name="CHILD_INDEX" )
    @JoinColumn(name="parent_id")
    private List<OrderChild> children;

    @Override
    public List<OrderChild> getChildren() {
        if(null==children){
            children = new ArrayList<OrderChild>();
        }
        return children;
    }

    @Override
    public OrderChild newChild(@DsLabel("Child name")String childName) {
        return new OrderChild(childName);
    }

    @Override
    public OrderParent addNumberOfChildren(@DsLabel("Number of children")int numberOfChildren) {
        return super.addChildren(numberOfChildren);
    }
    
}
